import { createSlice } from "@reduxjs/toolkit";
interface InitialState {
  count: number,
  userUrl: string,
  nickName: string,
  language: string,
  gender: number,
  country: string,
  city: string,
  province: string,
  signature: string,
  rawData: string,
  iv: string,
  errMsg: string,
  encryptedData: string,
  cloudID: string,
  userInfo: any,
  avatarUrl: string,
}
const initialState: InitialState = {
  count: 0,
  userUrl: '',
  nickName: '',
  language: '',
  gender: 0,
  country: "",
  city: "",
  province: '',
  signature: '',
  rawData: '',
  iv: '',
  errMsg: '',
  encryptedData: '',
  cloudID: '',
  userInfo: {},
  avatarUrl: '',
};

export const stateSlice = createSlice({
  name: "state",
  initialState,
  reducers: {
    setUserinfo(state, { payload }){
      const { userInfo } = payload;
      Object.keys(userInfo).forEach(key => {
         state[key] = userInfo[key];
      });
      Object.keys(userInfo?.userInfo).forEach(key => {
        state[key] = userInfo?.userInfo?.[key];
      })
    }
  }
});
export const { setUserinfo } = stateSlice.actions;
export default stateSlice.reducer;




